package com.hooda.framework.orm;

import com.alibaba.druid.pool.DruidDataSource;
import com.hooda.framework.annotations.Autowired;
import com.hooda.framework.annotations.Component;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author 应癫
 */
@Component
public class DruidManager {

    private DruidDataSource druidDataSource;

    public DruidManager() {
        druidDataSource = new DruidDataSource();
    }

    @Autowired("jdbc.driver")
    public void setDriverClassName(String driverClassName) {
        druidDataSource.setDriverClassName(driverClassName);
    }

    @Autowired("jdbc.url")
    public void setUrl(String url) {
        druidDataSource.setUrl(url);
    }

    @Autowired("jdbc.user")
    public void setUsername(String userName) {
        druidDataSource.setUsername(userName);
    }

    @Autowired("jdbc.password")
    public void setPassword(String password) {
        druidDataSource.setPassword(password);
    }

    public Connection getConnection() throws SQLException {
        return druidDataSource.getConnection();
    }
}
